<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>添加推送任务</title>
    {% load staticfiles %}
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

    <link rel="stylesheet" href="{% static 'lib/layui/css/layui.css' %}">
    <link rel="stylesheet" href="{% static 'css/scroll-bar.css' %}">
    <link rel="stylesheet" href="{% static 'css/sub-page.css' %}">

    <link rel="stylesheet" href="//at.alicdn.com/t/font_693759_wytlyqhtdtj1nhfr.css">
</head>
<body>
<div class="ok-body">
    <!--面包屑导航区域-->
    <div class="ok-body-breadcrumb">
            <span class="layui-breadcrumb">
                <a><cite>首页</cite></a>
                <a><cite>功能管理</cite></a>
                <a><cite>环境推送</cite></a>
				<a><cite>添加环境推送任务</cite></a>
            </span>
        <a class="layui-btn layui-btn-small" href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon layui-icon-refresh"></i>
        </a>
    </div>
    <!--form表单-->
    <form class="layui-form layui-form-pane ok-form">

            <div class="layui-form-item">
            <label class="layui-form-label">执行脚本</label>
            <div class="layui-input-block">
                <select name="scripts" lay-filter="loginuser">
                    <option value=""></option>
                    <option value="" selected=""></option>
                    {% for scriptobj in scriptL %}
                        <option value="{{ scriptobj.id }}">{{ scriptobj.zwname }}</option>
                    {% endfor %}
                </select>
            </div>
        </div>
                <div class="layui-form-item">
            <label class="layui-form-label">资产机器</label>
            <div class="layui-input-block">
                <select name="asset-id" lay-filter="network_ip">
                    <option value=""></option>
                    <option value="" selected=""></option>
                    {% for assetobj in assetlistsL %}
                        <option value="{{ assetobj.id }}">{{ assetobj.hostname }} --> {{ assetobj.ip_address }} -->{{ assetobj.status}}</option>
                    {% endfor %}
                </select>
            </div>
        </div>




        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <input name="remarks" placeholder="请输入内容" class="layui-input"></input>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
{#                <button class="layui-btn" lay-submit lay-filter="checkopen">测试连通性</button>#}
                <button class="layui-btn" lay-submit lay-filter="add">添加推送任务</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<!--js逻辑-->
<script src="{% static 'lib/layui/layui.js' %}"></script>
<script>
    layui.use(['element', 'form', 'jquery', 'laydate'], function () {
        var element = layui.element;
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        var laydate = layui.laydate;

        laydate.render({
            elem: '#birthday',
            type: "datetime"
        });

        {#form.verify({#}
        {#    birthdayVerify: [/^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))(\s(([01]\d{1})|(2[0123])):([0-5]\d):([0-5]\d))?$/, '日期格式不正确']#}
        {# });#}

        form.on('submit(add)', function (data) {
            console.log(data.field);

            data.field["flag"] = "0";

            $.ajax({
                type: 'post',
                url: "{% url 'api_remote_initbase_add' %}", // ajax请求路径
                data: {
                    data: JSON.stringify(data.field),
                    csrfmiddlewaretoken: "{{ csrf_token }}",
                },
                dataType: 'json',
                success: function (data) {
                    if (data["status"] == 0) {
                        layer.msg("添加成功！", {icon: 6, time: 1000, anim: 4}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                        });
                    } else if (data == 'error') {
                        layer.msg('添加失败');
                    }
                }
            });

            return false;
        });
        {#form.on('submit(checkopen)', function (data) {#}
        {#    console.log(data.field);#}
        {#    layer.msg('检测中...');#}
        {#    $.ajax({#}
        {#        type: 'post',#}
        {#        url: "{% url 'api_hosts_check_online' %}", // ajax请求路径#}
        {#        data: {#}
        {#            data: JSON.stringify(data.field),#}
        {#            csrfmiddlewaretoken: "{{ csrf_token }}",#}
        {#        },#}
        {#        dataType: 'json',#}
        {#        success: function (data) {#}
        {#            if (data["code"] == 0) {#}
        {#                layer.msg("验证成功！", {icon: 6, time: 2000, anim: 4},);#}
        {#            } else if (data["code"] != 0) {#}
        {#                layer.msg('验证失败:'+data["message"],{icon: 2, time: 2000, anim: 4});#}
        {#            }#}
        {#        }#}
        {#    });#}
        {##}
        {#    return false;#}
        {# });#}
    })
</script>
</body>
</html>